import {Component, OnInit, Input} from '@angular/core';
import {ActivatedRoute, Router, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot} from '@angular/router';
import {UserLoginService} from './user-login.service';
import {Observable} from 'rxjs/Observable';

import {User} from '../model/user-model';
import {fadeIn} from '../../animations/fade-in';

@Component({
  selector: 'app-user-login',
  templateUrl: './user-login.component.html',
  styleUrls: ['./user-login.component.scss'],
  animations: [fadeIn]
})
export class UserLoginComponent implements OnInit {
  public user: User = new User();
  public error: Error;

  constructor(public router: Router,
              public activatedRoute: ActivatedRoute,
              public userLoginService: UserLoginService) {
  }

  ngOnInit() {
    console.log(this.activatedRoute.url);
  }

  public doLogin(): void {
    this.userLoginService.login(this.user).subscribe(
      data => {
        if(data.error){
          this.error = data.error;
        }else{
          this.router.navigateByUrl('/');
        }
      },
      error => {
        console.error(error);
      }
    );
  }


  public forgetPwd(): void {
    this.router.navigateByUrl("forgetpwd");
  }
}
